#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../../../NetEngine_Linux/NetEngine_SourceCode/XyRyNet_CommHdr.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/XyRyNet_Types.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine_HelpComponents/HelpComponents_XLog/XLog_Define.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine_HelpComponents/HelpComponents_XLog/XLog_Error.h"

//g++ -std=gnu++11 -Wall -g Test_XLog.cpp -o Test_XLog -L ../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_BaseLib -L ../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_Client -L ../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_HelpComponents -lNetEngine_BaseLib -lNetClient_Socket -lHelpComponents_XLog -Wl,-rpath=../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_BaseLib:../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_Client:../../../NetEngine_Linux/NetEngine_Release/NetEngine_Release/NetEngine_HelpComponents,--disable-new-dtags

int main(int argc,char *argv[])
{
    HELPCOMPONENTS_XLOG_COLOR st_XLogColor;
    HELPCOMPONENTS_XLOG_CONFIGURE st_XLogConfig;

    memset(&st_XLogColor, '\0', sizeof(HELPCOMPONENTS_XLOG_COLOR));
    memset(&st_XLogConfig, '\0', sizeof(HELPCOMPONENTS_XLOG_CONFIGURE));

    st_XLogConfig.XLog_MaxSize = 102400;
    st_XLogConfig.XLog_MaxBackupFile = 10;

    _tcscpy_s(st_XLogConfig.st_BackInfo.tszBackDir, 128, _T("./back/"));
    _tcscpy_s(st_XLogConfig.tszFileName, MAX_PATH,_T("./log/test.log"));

    XLOG xhLog = HelpComponents_XLog_Init(HELPCOMPONENTS_XLOG_OUTTYPE_FILE | HELPCOMPONENTS_XLOG_OUTTYPE_STD,&st_XLogConfig);
    if (NULL == xhLog)
    {
        printf("HelpComponents_XLog_Init:%lX\n", XLog_GetLastError());
        return -1;
    }
    HelpComponents_XLog_SetLogPriority(xhLog, NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_DEBUG);

    XLOG_PRINT(xhLog, NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("xlog test 1=NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO"));
    XLOG_PRINT(xhLog, NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("xlog test 2=NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN"));
    XLOG_PRINT(xhLog, NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("xlog test 3=NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR"));

    st_XLogColor.wError = NETENGINE_HELPCOMPONENTS_XLOG_BACK_BLUE | NETENGINE_HELPCOMPONENTS_XLOG_TEXT_RED;
    st_XLogColor.wWarn = NETENGINE_HELPCOMPONENTS_XLOG_TEXT_GREEN;

    if (!HelpComponents_XLog_SetLogColor(xhLog, &st_XLogColor))
    {
        printf("HelpComponents_XLog_SetLogColor:%lX\n", XLog_GetLastError());
        return -1;
    }

    for (int i = 0;i < 10000;i++)
    {
        XLOG_PRINT(xhLog, NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("xlog test 1=%d NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO"),i);
        XLOG_PRINT(xhLog, NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("xlog test 2=%d NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN"),i);
        XLOG_PRINT(xhLog, NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("xlog test 3=%d NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR"),i);
        XLOG_PRINT(xhLog, NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("xlog test ok"));
    }

    HelpComponents_XLog_SetLogAllow(xhLog, NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO | NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN);
    XLOG_PRINT(xhLog, NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("xlog test"));
    XLOG_PRINT(xhLog, NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_WARN, _T("xlog test"));
    XLOG_PRINT(xhLog, NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _T("xlog test"));
    XLOG_PRINT(xhLog, NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO, _T("xlog test ok"));

    HelpComponents_XLog_Destroy(xhLog);
    return 0;
}
